﻿using System;
using System.ComponentModel;

namespace ExFlash.Records
{
    public enum SpreadMode : byte
    {
        PadMode = 0,
        ReflectMode = 1,
        RepeatMode = 2,
    }

    public enum InterpolationMode : byte
    {
        NormalRGB = 0,
        LinearRGB = 1
    }
    
    [TypeConverter(typeof(GradientConverter))]
    public class Gradient : ISwfSerializable
    {
        public ShapeType ShapeType
        {
            get;
            protected set;
        }
        
        public SpreadMode SpreadMode
        {
            get;
            protected set;
        }

        public InterpolationMode InterpolationMode
        {
            get;
            protected set;
        }

        public Byte NumGradients
        {
            get;
            protected set;
        }

        public GradRecord[] GradientRecords
        {
            get;
            protected set;
        }

        public Gradient(ShapeType type)
        {
            ShapeType = type;
        }

        #region ISwfSerializable Members

        public virtual void SwfDeserialize(BinaryBitReader reader)
        {
            SpreadMode = (SpreadMode)reader.ReadUInt32(2);
            InterpolationMode = (InterpolationMode)reader.ReadUInt32(2);
            NumGradients = (byte)reader.ReadUInt32(4);
            reader.AlignBits();

            GradientRecords = new GradRecord[NumGradients];

            for (int i = 0; i < NumGradients; i++ )
            {
                GradientRecords[i] = new GradRecord(ShapeType);
                GradientRecords[i].SwfDeserialize(reader);
            }
        }

        public virtual void SwfSerialize(byte[] arr, ref int offset)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    public class GradientConverter : ExpandableObjectConverter
    {

    }
}
